home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / fido / XPACK275.lha / rexx / ADDWORK.REXX next >
OS/2 REXX Batch file  |  1995-04-19  |  8KB  |  229 lines

  1. /**/
  2. v="$VER: AddWork Rexx   Queue files for a Site Williamson 53.16"
  3. options results
  4. options failat 20
  5. signal on syntax  
  6. signal on halt
  7. signal on ioerr
  8. signal on break_c
  9. signal on break_d
  10. parse arg site_address file disposition priority queuectl
  11. IF ARG()=0 THEN SIGNAL USAGE
  12. sv='v'||right(v,5)
  13. script='AddWork'
  14. log=show('P','ROOFLOG')
  15. if ~show("L", "xferq.library") then
  16.   if ~addlib("xferq.library", 0, -30, 0) then do
  17.   PutLog("Couldn't access xferq.library !",10,10)
  18.   exit 20
  19. end
  20. XQ_NOTHING   =0
  21. XQ_DELETE    =1
  22. XQ_TRUNCATE  =2
  23. XQ_IMMEDIATE =4
  24. XQ_SENDLATER =8
  25. XQ_IFSENT    =16
  26. DTPRI_CRASH  =50
  27. DTPRI_DIRECT =30 
  28. DTPRI_NORM   =0
  29. DTPRI_HOLD   =-50
  30.  
  31. wspec='RAW:0/10/640/100/'script sv'/INACTIVE/AUTO/SCREEN'||GetClip('SCREEN')
  32. call close('STDOUT');call open('STDOUT',wspec,'W');call close('STDIN');call open('STDIN','*','R')
  33. call myadr
  34. PutLog(site_address file disposition priority queuectl,70,70)
  35. if datatype(site_address,"MIXED") then isftn=0
  36. else do 
  37.   site_address=make5d(site_address)
  38.   isftn=1
  39. end
  40. if site_address=0 then return
  41. if file="" | ~(exists(file)) then do
  42.   PutLog('Cannot find ['file']',10,10)
  43.   return 1
  44. end
  45. file=upper(file)
  46. if right(file,4)=".REQ" then do
  47.   PutLog('REQ file:['file'] not queueable',10,10)
  48.   return 1
  49. end
  50. select
  51.   when upper(disposition)="D" then flags=XQ_DELETE
  52.   when upper(disposition)="T" then flags=XQ_TRUNCATE
  53.   when upper(disposition)="L" then flags=XQ_NOTHING
  54.   otherwise flags=XQ_NOTHING
  55. end
  56. if upper(queuectl)="A" then queuectl=XQ_SENDLATER
  57. else if upper(queuectl)="I" then queuectl=XQ_IMMEDIATE
  58. else if upper(queuectl)="K" then queuectl=XQ_IMMEDIATE+XQ_IFSENT
  59. else queuectl=XQ_NOTHING
  60. select
  61.   when priority>50 then nop
  62.   when priority>30 then priority=DTPRI_CRASH
  63.   when priority>0 then priority=DTPRI_DIRECT
  64.   when priority=0 then priority=DTPRI_NORM
  65.   when priority= -50 then priority=DTPRI_HOLD
  66.   otherwise priority=DTPRI_CRASH
  67. end
  68. added=0
  69. if ~isftn then do
  70.   sendas=get_fn(file)
  71.   site=site_address
  72. end;else do
  73.   if right(file,4)=".CUT" | right(file,4)=".DUT" | right(file,4)=".HUT" | right(file,4)=".OUT" then do
  74.   sendas=get_packetname()
  75.   flags=XQ_DELETE
  76. end;else if right(file,4)=".PKT" | right(file,4)=".TIC" then do
  77.   sendas=get_fn(file)
  78.   flags=XQ_DELETE
  79. end;else do
  80.   parse var file td'.'tz'.'tn'.'tf'.'tp'.'ext .
  81.   if arcmailext(ext) then call addarcmail  
  82.   /*if ext ~= "" then call addarcmail */
  83.   else do
  84.     parse var file tz'.'tn'.'tf'.'tp'.'ext .
  85.     /*if ext ~= "" then call addarcmail */
  86.     if arcmailext(ext) then call addarcmail
  87.   else do
  88.     sendas=get_fn(file)
  89.   end
  90. end
  91. drop td tz tn tf tp ext tmpext j 
  92. end
  93. site=hisaddress.domain||"#"||hisaddress.zone||":"||hisaddress.net||"/"||hisaddress.node||"."||hisaddress.point
  94. end
  95.  
  96. site_address=XfqGetAddress(site)
  97. QUERY.XQ_NAME=file
  98. QUERY.XQ_SITE=site_address
  99. work=NULL
  100. work=XfqFindWork(QUERY)
  101. if work=NULL then do
  102. PutLog("File "file" not in "site" queue, adding",60,10)
  103. XfqAddWorkQuick(site,file,sendas,priority,flags+queuectl)
  104. added=1
  105. end;else do
  106. PutLog("File "file" already queued for "site,60,10)
  107. if work ~= NULL then call XfqUnlockWork(work)
  108. end
  109. call XfqFlushQueue(site_address)
  110. call XfqDropObject(site_address)  
  111. if work ~= NULL then  do
  112. call XfqDropObject(work)  
  113.     if isftn then call PutLog('Queued 'file' as 'sendas' for 'hisaddress.zone':'hisaddress.net'/'hisaddress.node'.'hisaddress.point' Pri:'priority 'Dsp:'flags+queuectl,10,10)
  114.     else call PutLog('Queued 'file' as 'sendas' for 'site_address' Pri:'priority 'Dsp:'flags+queuectl,10,10)
  115. end
  116. call XfqClose()
  117. exit
  118. addarcmail:
  119. tmpext=upper(left(ext,2))
  120. if datatype(right(ext,1),'n') & (tmpext="MO" | tmpext="TU" | tmpext="WE" | tmpext="TH" | tmpext="FR" | tmpext="SA" | tmpext="SU")  then do
  121. sendas=UPPER(d2x(65536+myaddress.net-tn,4)||d2x(65536+myaddress.node-tf,4)||'.'ext)
  122. flags=XQ_DELETE
  123. end
  124. return
  125. get_packetname:
  126. if ~open('out',"CFG:packet_spec",'R') then call PutLog("Can't read packet_spec file",70,10)
  127. else DO
  128. packet_spec=readln('out')
  129. close('out')
  130. END
  131. tspec=left(date(), 2) || compress(time(), ":")
  132. if (tspec=packet_spec) then tspec=tspec+1
  133. do while exists(BUNDLES||tspec".PKT") 
  134. tspec=tspec + 1   
  135. end   
  136. if ~open('out',"CFG:packet_spec",'W') then call PutLog("Can't write new packet_spec file",10,10)
  137. else DO
  138. writeln('out',tspec)
  139. close('out')
  140. END
  141. return(tspec||".PKT")
  142. get_fn:
  143. if LastPos('/', arg(1)) ~= 0 then return SubStr(arg(1), LastPos('/', arg(1)) + 1)
  144. else if LastPos(':', arg(1)) ~= 0 then return SubStr(arg(1), LastPos(':', arg(1)) + 1)
  145. else return arg(1)
  146. make5d: 
  147. a=strip(arg(1))
  148. select
  149. when index(a, "#") > 0 then parse var a hisaddress.domain "#" hisaddress.zone ":" hisaddress.net "/" hisaddress.node "." hisaddress.point
  150. when index(a, ":") > 0 then parse var a hisaddress.zone ":" hisaddress.net "/" hisaddress.node "." hisaddress.point
  151. when index(a, "/") > 0 then parse var a hisaddress.net "/" hisaddress.node "." hisaddress.point
  152. when index(a, ".") > 0 then parse var a hisaddress.node "." hisaddress.point
  153. when left(a, 1)="." then parse var a "." hisaddress.point
  154. otherwise parse var a hisaddress.node .
  155. end
  156. call myadr    
  157. if hisaddress.point="" | hisaddress.point='HISADDRESS.POINT' then hisaddress.point="0"
  158. if hisaddress.net  ="" | hisaddress.net  ='HISADDRESS.NET'   then hisaddress.net  =myaddress.net
  159. if hisaddress.node ="" | hisaddress.node ='HISADDRESS.NODE'  then hisaddress.node =myaddress.node
  160. if hisaddress.zone ="" | hisaddress.zone ='HISADDRESS.ZONE'  then hisaddress.zone =myaddress.zone
  161. if hisaddress.domain="" | hisaddress.domain ='HISADDRESS.DOMAIN' then hisaddress.domain=find_domain(hisaddress.zone)
  162. drop a
  163. return(hisaddress.domain'#'hisaddress.zone':'hisaddress.net'/'hisaddress.node'.'hisaddress.point)
  164. myadr:
  165. def_domain=GetClip('DOMAIN')
  166. myaddress.domain=GetClip('DOMAIN')
  167. cfgaddress=GetClip('HOST.ADDRESS.'||myaddress.domain)
  168. parse var cfgaddress myaddress.zone ":" myaddress.net "/" myaddress.node "." myaddress.point
  169. myaddress.pointnet=GetClip('POINTNET')
  170. if def_domain="" then do
  171.     address COMMAND 'SetEnv HOSTADDR `type XFERQ:hostaddr`'
  172.     myaddress=GetVar('HOSTADDR','G')
  173.     parse var myaddress myaddress.domain'#'myaddress.zone':'myaddress.net'/'myaddress.node'.'myaddress.point .
  174.     def_domain=myaddress.domain
  175. end
  176. return(myaddress.zone':'myaddress.net'/'myaddress.node'.'myaddress.point)
  177. find_domain:
  178. dl=GetClip('DOMAINLIST')
  179. if dl="" then return def_domain
  180. dz=FIND(dl,arg(1))
  181. if dz=0 then return def_domain
  182. else return strip(word(dl,dz-1))
  183. PutLog:  procedure expose log script
  184. say arg(1)
  185. if log then address 'ROOFLOG' 'logline' left(time(),5) script': 'arg(1)
  186. return 0
  187. cleanup:
  188. call XfqClose()
  189. return 0
  190. break_c:
  191. break_d:
  192. PutLog('User Abort',10,10)
  193. call cleanup
  194. exit 10
  195. novalue: 
  196. call template_oops "Novalue" sigl
  197. syntax:
  198. call template_oops "Syntax(RC=" || RC || ")" sigl RC
  199. failure:
  200. call template_oops "Failure(RC=" || RC || ")" sigl
  201. ioerr:
  202. call template_oops "IOErr(RC=" || RC || ")" sigl 
  203. halt:
  204. call template_oops "Halt" sigl 
  205. template_oops: 
  206. parse arg what badline code
  207. if code~="" then call PutLog("ERR:"what "Line:"badline errortext(code),10,60)
  208. else PutLog("ERR:"what "Line:"badline,10,10)
  209. call cleanup
  210. exit(40)
  211. USAGE:
  212. SAY "    ADDWORK site_address fullname disposition priority queuectl"
  213. SAY "    disposition: D=delete"
  214. SAY "                 T=truncate to zero bytes"
  215. SAY "                 L=do nothing    (default)"
  216. SAY "    priority:    (-128 to +128)  (default 50)"
  217. SAY "    queuectl:    I=queue only if connected to site"
  218. SAY "                   always execute disposition"
  219. SAY "                 K=queue only if connected to site,"
  220. SAY "                   ignore disposition if not sent"
  221. SAY "                 A=queue after current session with site"
  222. SAY ""   
  223. SAY "   if file is *.?UT then it will be sent as a *.PKT"
  224. SAY "   if file is ARCmail, sendas name will be created"
  225. SAY "   Both default to disposition=D and priority 50"
  226. RETURN
  227.  
  228. arcmailext: return (length(arg(1))=3 & pos(left(arg(1),2),'MO TU WE TH FR SA SU')>0 & datatype(right(arg(1),1),N))
  229.